// pages/andon_kanban/xqjyzz/xqjyzz.js
const mybehavior = require("../../../behaviors/requests")
Page({

  /**
   * 页面的初始数据
   */
  behaviors: [mybehavior],
  data: {
    page_all: 1,
    location: "商用总装",
    columns: [{
        title: '网关编号',
        dataIndex: 'raspberry_num',
        key: 'raspberry_num',
        width: 125,
        align: 'center',
      },
      {
        title: '安装位置',
        dataIndex: 'work',
        key: 'work',
        width: 125,
        align: 'center',
      },
      {
        title: '上次心跳时间',
        dataIndex: 'heart_time',
        key: 'heart_time',
        width: 150,
        align: 'center',
      },
      {
        title: '状态',
        dataIndex: 'state',
        key: 'state',
        width: 80,
        align: 'center',
      },
    ],
    data: [],
    pagination: {
      defaultCurrent: 1,
      hideOnSinglePage: true,
      total: 0,
      current: 1,
      pageSize: 10,
    }
  },
  pageUp() {
    let pagination = this.data.pagination;
    if (pagination.current != 1) {
      pagination.current = pagination.current - 1
      this.setData({
        pagination: pagination,
      })
      this.get_tableData()
    }
  },
  pageDown() {
    let pagination = this.data.pagination
    if (pagination.current < this.data.page_all + 1) {
      pagination.current = pagination.current + 1
      this.setData({
        pagination: pagination,
      })
      this.get_tableData()
    }
  },
  get_tableData() {
    let that = this;
    this.get('http://logisticsengineering.gree.com/andon_system/get_getway_info', {
      'location': that.data.location,
      'current': that.data.pagination.current
    }).then(res => {
      that.setData({
        page_all: parseInt(that.data.pagination.total / that.data.pagination.pageSize)
      })
      let pagination = that.data.pagination;
      pagination.total = res.table_total;
      that.setData({
        data: res.table_data,
        pagination: pagination
      })
      console.log(res.table_data)
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.get_tableData()
    setInterval(() =>
      this.get_tableData(), 5000)
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})